package org.foundation.jala.jamerzip.modelzip;

import java.io.File;

import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

import org.foundation.jala.jamerzip.view.NewZipView;

public class NewZip {

	private DefaultListModel modelList;
	
	private NewZipView view;
	
	public NewZip(JFrame father) {
		this.view = new NewZipView(father);
		this.view.setActions(this);
		this.modelList = new DefaultListModel();
		this.view.getList().setModel(modelList);
	}
	
	public void addFile() {
		JFileChooser fc = new JFileChooser(System.getProperty("user.home"));
		fc.setDialogTitle("Add to Compress");
		fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
		fc.setMultiSelectionEnabled(true);
		int result = fc.showOpenDialog(new JFrame());
		if (result == JFileChooser.APPROVE_OPTION) {
			File[] paths = fc.getSelectedFiles();
			for (File file : paths) {
				if(!modelList.contains(file.getAbsolutePath())){
					modelList.addElement(file.getAbsolutePath());
				}
			}
		}
	}
	
	public void showTargetPath(){
		JFileChooser fc = new JFileChooser(System.getProperty("user.home"));
		fc.setDialogTitle("Dest");
		fc.setMultiSelectionEnabled(true);
		int result = fc.showSaveDialog(new JFrame());
		if (result == JFileChooser.SAVE_DIALOG) {
			this.view.getDir().setText("NewZip.zip");
		}
	}
	public void compress() {

	}

	@SuppressWarnings("deprecation")
	public void showView(){
		view.show();
	}
}
